package org.devocean.groupbuying.service.impl;

import org.devocean.groupbuying.dao.UserDao;
import org.devocean.groupbuying.domain.User;
import org.devocean.groupbuying.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;

	@Transactional(readOnly = true)
	public User getUserById(Integer id) {

		return userDao.findUserById(id);
	}

	@Transactional
	public User addOrUpdateUser(User user) {
		if (user.getUserID() == null)
			return userDao.saveUser(user);
		else {
			return userDao.updateUser(user);
		}
	}

	@Transactional
	public void removeUser(Integer id) {
		userDao.deleteUser(id);

	}

	public long countUsers() {
		return userDao.countUser();
	}


	public User findUserByUserName(String userName) {
		return userDao.findUser(userName);
	}

}
